package main

import (
	"fmt"
	"reflect"
)

type Tangzq struct {
	Info  Info
	Car   Car
	House House
	Name  string
	Phone string
}

type Info struct {
	Name      string
	SmallName string
	Age       int
	Area      string
	Country   string
}

type Car struct {
	Brand string
	Color string
	Type  string
}

type House struct {
	Address string
	Type    string
	Age     int
}

func main() {
	me := Tangzq{
		Info: Info{
			Name:      "tangzq",
			SmallName: "qiangqing",
			Age:       80,
			Area:      "chengdu",
			Country:   "china",
		},
		Car: Car{
			Brand: "byd",
			Color: "white",
			Type:  "SUV",
		},
		House: House{
			Address: "sichuan.chengdu",
			Type:    "normal",
			Age:     11,
		},
		Name:  "tangzq",
		Phone: "13552807156",
	}
	// fmt.Printf("%+v \n", me)
	t := reflect.TypeOf(me)
	v := reflect.ValueOf(me)
	fmt.Printf("type:%v  kind:%v \n", t.Name(), t.Kind())
	fmt.Printf("%+v \n", v.Kind())

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		fmt.Printf("name: %s index: %d type:%v json tag: %v kind: %v \n", field.Name, field.Index, field.Type, field.Tag.Get("json"), field.Type.Kind())
	}

	//通过字段名获取指定字段
	if f, ok := t.FieldByName("Name"); ok {
		fmt.Printf("name: %s index: %d type:%v json tag: %v \n", f.Name, f.Index, f.Type, f.Tag.Get("json"))
	}
}

//递归自己，把一个值加到100，然后结束
func recursion(first *int, target int) {
	*first++
	// fmt.Printf("现在的值是:%d \n", *first)
	//这个地方是递归结束的条件
	if *first == target {
		return
	}

	recursion(first, target)
}
